﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using control.Dal;
using System.Collections;

namespace control.Biz
{
    public class BizChiTietPhieuNhap
    {
        private BizPhieuNhap phieuNhap;
        public BizPhieuNhap PhieuNhap
        {
            set { phieuNhap = value; }
            get 
            {
                if (phieuNhap == null)
                    phieuNhap = new BizPhieuNhap();
                return phieuNhap;
            }
        }
        private BizSach sach;
        public BizSach Sach
        {
            set { sach = value; }
            get
            {
                if(sach==null)
                    sach= new BizSach();
                return sach;
            }
        }
        public string MaSach
        {
            get { return Sach.MaSach; }
        }
        public int SoLuong { get; set; }
        public int DonGia { get; set; }


        internal static List<BizChiTietPhieuNhap> GetListByIDPhieu(int p)
        {
            return DalChiTietPhieuNhap.GetListByIDPhieu(p) ;
        }

        internal void Inset()
        {
            DalChiTietPhieuNhap.Insert(this);
            BizTonKho tonkho = new BizTonKho()
            {
                IDSach = this.Sach.IdSach,
                ThoiGian = this.PhieuNhap.NgayNhap,
                SoLuong=DalTonKho.GetLastByIDSach(this.Sach.IdSach,this.phieuNhap.NgayNhap)+this.SoLuong,
            };
            tonkho.Insert();
        }



        internal static void DeleteCTofPhieu(BizPhieuNhap bizPhieuNhap)
        {
            foreach (BizChiTietPhieuNhap item in bizPhieuNhap.Items)
	        {
                DalTonKho.DeleteByIDSach_TG(item.Sach.IdSach, bizPhieuNhap.NgayNhap);
	        }
            DalChiTietPhieuNhap.DeleteCTofPhieu(bizPhieuNhap);
            
        }
    }
}
